package com.shiro.receiver.handler;

import lombok.extern.slf4j.Slf4j;
import com.shiro.receiver.framework.constant.BotEventType;
import com.shiro.receiver.framework.constant.BotOperationType;

import java.util.*;

@Slf4j
public class EventHandlerStorage {

    private static final Map<BotOperationType, Map<BotEventType, List<AbstractEventHandler>>> HANDLER_MAP = new HashMap<>();

    public static void register(BotOperationType operation, BotEventType type, AbstractEventHandler handler) {
        HANDLER_MAP.computeIfAbsent(operation, k -> new HashMap<>());
        HANDLER_MAP.get(operation).computeIfAbsent(type, k -> new ArrayList<>()).add(handler);
        log.info("[EventHandler注册成功] [operation:{}] [Type:{}] [Name:{}]", operation, type, handler.getClass().getSimpleName());
    }

    public static List<AbstractEventHandler> getEventHandlerList(BotOperationType operation, BotEventType type) {
        return HANDLER_MAP.getOrDefault(operation, Collections.emptyMap()).getOrDefault(type, Collections.emptyList());
    }

}
